var redisCluster = require('fast-redis-cluster2').clusterClient;

var opts = config.redis

var cluster = new redisCluster.clusterInstance(opts, function (err) {
    if (err) console.error(err);

    console.log('Connected, cluster is fine and ready for using');
});

cluster.on('ready', function () {
    console.log('Connected, cluster is fine and ready for using');
});

cluster.on('error', function (err) {
    console.error('Redis error', err);
});

exports.set = (key, val, ex, cb) => {
    cluster.set(key, val, 'EX', ex, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.get = (key, cb) => {
    cluster.get(key, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.get = (key, cb) => {
    cluster.get(key, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.hmset = (key, obj, cb) => {
    cluster.hmset(key, obj, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.hgetall = (key, cb) => {
    cluster.hgetall(key, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.del = (key, cb) => {
    cluster.del(key, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}

exports.expire = (key, ttl, cb) => {
    cluster.expire(key, ttl, (errRedis, dataRedis) => {
        cb(errRedis, dataRedis)
    })
}